import java.util.Random;
public class Main {

    /**
     * 测试使用q运行op个enqueue和dequeue所需要的时间
     * @param q
     * @param opCount
     * @return
     */
    private static double testQueue(Queue<Integer> q,int opCount){

        long startTime = System.nanoTime();

        //...
        Random random = new Random();
        for (int i = 0; i < opCount; i++) {
            q.enqueue(random.nextInt(Integer.MAX_VALUE));//将[0-Max]其中的一数传进

        }

        for (int i = 0; i < opCount; i++) {
            q.dequeue();
        }
        long endTime = System.nanoTime();


        return (endTime - startTime) / 1000000000.0;
    }
    public static void main(String[] args) {

        int opCount = 100000;
        ArrayQueue<Integer> arrayQueue = new ArrayQueue<>();
        double time1 = testQueue(arrayQueue,opCount);
        System.out.println("ArrayQueue,time:"+time1+"s");

        LoopQueue<Integer> loopqueue = new LoopQueue <> ();
        double time2 = testQueue(loopqueue,opCount);
        System.out.println("loopqueue,time:"+time2+"s");

        LinkedListQueue<Integer> linkqueue = new LinkedListQueue <> ();
        double time3 = testQueue(linkqueue,opCount);
        System.out.println("linkqueue,time:"+time3+"s");


    }
}
